/** 数组栈 */
export default class ArrayStack {
  private stackArray: any[];
  /** 栈长度 */
  private stackLength: number;
  /** 当前元素个数 */
  private ele_number: number;
  constructor(n: number) {
    // 初始化一个 n 长度得数组栈
    this.stackArray = new Array(n);
    this.stackLength = n;

    this.ele_number = 0;
  }

  /** 入栈 */
  public push(value: any) {
    if (this.ele_number == this.stackLength) {
      console.log('入栈失败，栈已满', this.stackArray);

      return -1;
    }

    this.stackArray[this.ele_number++] = value;
  }

  /** 出栈 */
  public pop() {
    if (this.ele_number == 0) {
      console.log('出站失败，栈已空');
      return -1;
    }
    const value = this.stackArray[this.ele_number-- - 1];
    console.log(value);
    return value;
  }
}

const stack = new ArrayStack(5);

stack.push('h');
stack.push('e');
stack.push('l');
stack.push('l');
stack.push('o');
stack.push('!');

stack.pop();
stack.pop();
stack.pop();
stack.pop();
stack.pop();
stack.pop();
